using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Entidades;
using Jetaime;

namespace Jetaime.Socio
{
/*
    EL CONTROLLER CONOCE LA VISTA (FORMULARIO) Y EL MODELO (ACCESO A DATOS). 
*/
    class SocioController
    {

    #region PROPIEDADES
      private SocioModel sModel;
      private Jetaime.SocioView sView;
      private String ABM = String.Empty;
      private SocioE socio;
    #endregion

    #region CONSTRUCTORES

      public SocioController(String ABM)
      {
        sModel = new SocioModel();
        sView = new Jetaime.SocioView();
        this.ABM = ABM;
        if (ABM == "M")
        {
          sView.txtIdCliente.Enabled = false;          
        }
        InitEvents();
      }

      public SocioController(String ABM, SocioE socio): this(ABM)
      {
        this.socio = socio;
        this.CargarTextBox(socio);
      }

    #endregion

    #region InitEvent

      private void InitEvents()
      {
          sView.btnAceptar.Click += new EventHandler(btnAceptar_Click);
          sView.btnCancelar.Click += new EventHandler(btnCancelar_Click);
      }

    #endregion

    #region Eventos

      private void btnAceptar_Click(object sender, EventArgs e)
      {
        socio = this.CargarSocio();
        sModel.GuardarSocio(this.ABM, socio);
        sView.Close();
      }

      void btnCancelar_Click(object sender, EventArgs e)
      {
        sView.Close();
      }

    #endregion

    #region Metodos

      public void Show()
      {
          sView.ShowDialog();
      }

      private void CargarTextBox(SocioE socioE)
      {
          sView.txtApellido.Text = socioE.Apellido;
          sView.txtCalle.Text = socioE.Calle;
          sView.txtDepartamento.Text = socioE.Departamento;
          sView.txtIdCliente.Text = socioE.Socio;
          sView.txtMail.Text = socioE.Mail;
          sView.txtNombre.Text = socioE.Nombre;
          sView.txtNumero.Text = socioE.Numero;
          sView.txtPiso.Text = socioE.Piso;
          sView.txtTelCelular.Text = socioE.TelefonoCelular;
          sView.txtTelParticular.Text = socioE.TelefonoParticular;
          sView.txtMail.Text = socioE.Mail;
      }

      private SocioE CargarSocio()
      {
        SocioE socio = new SocioE();
        socio.Apellido = sView.txtApellido.Text;
        socio.Calle = sView.txtCalle.Text;
        socio.Departamento = sView.txtDepartamento.Text;
        socio.Socio = sView.txtIdCliente.Text;
        socio.Mail = sView.txtMail.Text;
        socio.Nombre = sView.txtNombre.Text;
        socio.Numero = sView.txtNumero.Text;
        socio.Piso = sView.txtPiso.Text;
        socio.TelefonoCelular = sView.txtTelCelular.Text;
        socio.TelefonoParticular = sView.txtTelParticular.Text;
        socio.Mail = sView.txtMail.Text;

        return socio;
      }

    #endregion

  }
}
